﻿using Ross.Service;
using Ross.Service.Dto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Web.Http;
using System.Web.Http.Results;
using System.Web.Http.Controllers;
using Ross.EntityFramework.Model;
using Ross.EntityFramework;

namespace Ross.Traning.Controllers
{
    [SimpleAuthenticationFilter]
    public class ExamDBController : BaseApiController
    {
        [HttpPost]
        public JsonResult<ResultDto<bool>> Insert([FromBody] Service.Dto.ExamDB vm)
        {
            ResultDto<bool> result = new ResultDto<bool>();
            using (ExamDBService serv = new ExamDBService(dbContextStr))
            {
                result = serv.Create(vm);
            }
            return Json(result);
        }
        [HttpPost]
        public JsonResult<ResultDto<bool>> Update([FromBody] Service.Dto.ExamDB vm)
        {
            ResultDto<bool> result = new ResultDto<bool>();
            using (ExamDBService serv = new ExamDBService(dbContextStr))
            {
                result = serv.Update(vm);
            }
            return Json(result);
        }

        [HttpPost]
        public JsonResult<ResultDto<bool>> Delete(int id)
        {
            ResultDto<bool> result = new ResultDto<bool>();
            using (ExamDBService serv = new ExamDBService(dbContextStr))
            {
                result = serv.Delete(id);
            }
            return Json(result);
        }
        [HttpGet]
        public JsonResult<ResultDto<List<Service.Dto.ExamDB>>> GetList()
        {
            ResultDto<List<Service.Dto.ExamDB>> result = new ResultDto<List<Service.Dto.ExamDB>>();
            using (ExamDBService serv = new ExamDBService(dbContextStr))
            {
                result = serv.GetAllList();
            }
            return Json(result);
        }
        [HttpGet]
        public JsonResult<ResultDto<List<Service.Dto.ExamDB>>> GetPageList(
            int pageIndex = 1,
            int pageSize = 20,
            string keywords = ""
        )
        {
            ResultDto<List<Service.Dto.ExamDB>> result = new ResultDto<List<Service.Dto.ExamDB>>();
            using (ExamDBService serv = new ExamDBService(dbContextStr))
            {
                result = serv.GetPageList(pageIndex, pageSize, keywords);
            }
            return Json(result);
        }
        [HttpGet]
        public JsonResult<ResultDto<Service.Dto.ExamDB>> GetByID(int id)
        {
            ResultDto<Service.Dto.ExamDB> result = new ResultDto<Service.Dto.ExamDB>();
            using (ExamDBService serv = new ExamDBService(dbContextStr))
            {
                result = serv.GetByID(id);
            }
            return Json(result);
        }
        [HttpGet]
        public JsonResult<ResultDto<List<string>>> GetClassName()
        {
            ResultDto<List<string>> result = new ResultDto<List<string>>();
            using (ExamDBService serv = new ExamDBService(dbContextStr))
            {
                result = serv.GetClassName();
            }
            return Json(result);
        }
    }
}